<div class="col-lg-12">

	<h3>Curent networks</h3>
	<table class="table table-bordered">
	  	<thead>
	  		<th>Network Type</th>
	  		<th>Network name</th>
	  		<th>Publisher ID / AppId</th>
	  		<th>Password / SecretKey</th>
	  		<th>Ratio</th>
	  		<th>Postback(don't change)</th>
	  		<th>lock</th>
	  		<th>Action</th>
	  	</thead>
	  	<tbody>
	  		
	  		<?php foreach ($networks as $network) { ?>

	  			<tr>
	  				
		  			<?php if( $network->networkType == 0 ) {?>
		  				<td>Wall <?php echo $network->networkType ; ?></td>
		  			<?php } else{?>
		  				<td>Banner <?php echo $network->networkType ; ?></td>
		  			<?php } ?>

		  			<td>
		  				<input class="form-control input-sm networkName" type="text" value="<?php echo $network->networkName ?>" />
		  			</td>

		  			<td>
		  				<input class="form-control input-sm pubId" type="text" value="<?php echo $network->pubIdOrAppId ?>" />
		  				<a href="#"><font size="2">Help!</font></a>
		  			</td>

		  			<td>
		  				<input id="password" class="form-control input-sm secretKey" type="password" value="<?php echo $network->passOrSecretKey ?>" />
		  				<a href="#"><font size="2">Help!</font></a>
		  			</td>


		  			<td>
		  				<input class="form-control input-sm ratio" type="text" value="<?php echo $network->ratio ?>" />
		  				<a href="#"><font size="2">Help!</font></a>
		  			</td>


		  			<td style="cursor:not-allowed;">
						<input class="form-control input-sm" value='<?php echo site_url("/postbacks/$network->postback") ?>' />
		  				<a href="#"><font size="2">Help!</font></a>
		  			</td>


		  			<td>
		  				<input class="lock" type="checkbox" <?php if($network->lockStatus == 1) echo "checked"; ?> /> 
		  			</td>

		  			<td>
						  <button data-networkId='<?php echo $network->networkId ?>' type="button" class="btn btn-info btn-save">
						  	<span class="glyphicon glyphicon-save"></span> 
						  	Save
						  </button>			
					</td>
		  		</tr>	  				

	  		<?php } ?>

	  			


	  	</tbody>
	</table>
	
</div>


<script type="text/javascript">
	$(document).ready(function() {
		
		$(".btn-save").click(function(event) {
			
			var networkId = $(this).attr('data-networkId');
			var v_tr = $(this).closest('tr');
			var networkName = v_tr.find('.networkName').val();
			var pubId = v_tr.find('.pubId').val();
			var secretKey = v_tr.find('.secretKey').val();
			var ratio = v_tr.find('.ratio').val();
			var cbx_lock = v_tr.find('.lock');

			var lock = (cbx_lock.is(':checked')) ? 1 : 0;

			var urlTest = site_url + 'admin/networks/edit/' + networkId + "/" + networkName + "/" + pubId + "/" + secretKey + "/" + ratio + "/" + lock;
			console.log(urlTest);

			

			console.log(lock);

		      $.ajax({
		        url: site_url + 'admin/networks/edit/' + networkId + "/" + networkName + "/" + pubId + "/" + secretKey + "/" + ratio + "/" + lock,
		        type: 'POST'
		      })
		      .done(function (response, textStatus, jqXHR){
		      		// location.reload();

		      })
		      .fail(function (response, textStatus, jqXHR){

		        alert('error');
		      })
		      .always(function (response, textStatus, jqXHR){

		      });


		});
	});
</script>

<!--
<script type="text/javascript" src='<?php echo  base_url("assets/js/network/edit_network.js") ?>'></script>
-->